#![no_std]
#![no_main]
#![feature(naked_functions)]

extern crate alloc;

#[macro_use]
extern crate syscall;

use core::hint::spin_loop;

use alloc::string::ToString;

mod malloc;

#[unsafe(no_mangle)]
extern "C" fn _start() -> ! {
    let fd = syscall::op::open(
        "/user/realinit.elf".to_string(),
        syscall::op::OpenMode::Read,
    );
    let mut buf = alloc::vec![0u8; syscall::op::fsize(fd)];
    syscall::op::read(fd, &mut buf);
    syscall::op::execve(&buf, 0, 0);

    loop {
        spin_loop();
    }
}

#[panic_handler]
fn panic(info: &core::panic::PanicInfo) -> ! {
    println!("{}", info);
    syscall::op::exit(1)
}
